<?php

class Musica {

    public function searchGoear($termino, $page) {
        Load::lib('expresiones');
        $termino = str_replace(" ", "+", $termino);
        $direc = "http://www.goear.com/search.php?q=" . $termino . "&p=" . ($page) . "";
        $direc = "http://www.goear.com/search/" . $termino . "/" . ($page) . "";
		//<a title="Escuchar mana - mana" href="listen/a85f69f/mana-mana"><span class="song">mana</span> - <span class="group">mana</span>
        //$direc = "http://www.goear.com/reqsearch.php?q=" . $termino . "&p=" . ($page - 1) . "";
        @$fuente = Expresiones::fuente($direc, true);
        //preg_match_all("/<a target=\'_parent\' href=\'http://www.goear.com\/listen\/(.*?)\/.*?\'>(.*?)<\/a>/", $fuente, $dato);
        //preg_match_all("/<a title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"song\">(.*?)<\/span> - <span class=\"group\">.*?<\/span><\/a>/", $fuente, $dato);
        //preg_match_all("<a title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"song hide\">Entra en goear.com o descarga gratis la aplicación goear mobile<\/span> <span class=\"songtitle\">(.*?)<\/span> - <span class=\"groupname\">.*?<\/span><\/a>/", $fuente, $dato);
        //preg_match_all("/<a title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"song hide\">.*?<\/span> <span class=\"songtitle\">(.*?)<\/span> - <span class=\"groupname\">.*?<\/span><\/a>/", $fuente, $dato);
        //preg_match_all("/<a title=\".*?\" title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"song hide\">.*?<\/span> <span class=\"songtitle\">(.*?)<\/span> - <span class=\"groupname\">.*?<\/span><\/a>/", $fuente, $dato);
        //preg_match_all("/<a title=\".*?\" title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"song hide\">.*?<\/span> <span class=\"songtitle\">(.*?)<\/span> - <span class=\"groupname\">.*?<\/span><\/a>/", $fuente, $dato);
        //preg_match_all("/<a title=\".*?\" href=\"listen\/(.*?)\/.*?\"><span class=\"songtitleinfo\">(.*?)<\/span> - <span class=\"groupnameinfo\">.*?<\/span><\/a>/", $fuente, $dato);
        preg_match_all("/<a title=\".*?\" href=\"http:\/\/www.goear.com\/listen\/(.*?)\/.*?\">.*?<span class=\"song\">(.*?)<\/span> - <span class=\"group\">.*?<\/span><\/a>/",$fuente, $dato);
        if (count($dato[0]) > 0) {
            //Load::lib('general');
            for ($i = 0; $i < count($dato[0]); $i++) {
                $return[$i]['id'] = $dato[1][$i];
                $return[$i]['titulo'] = $dato[2][$i];
                @$return[$i]['tituloUrl'] = General::slugify($dato[2][$i]);
            }
        }
        else
            $return = false;
        return $return;
        //return $dato;
    }

    public function searchGoear2($termino, $page) {
        Load::lib('expresiones');
        $termino = str_replace(" ", "+", $termino);
        $direc = "http://www.goear.com/reqsearch.php?q=" . $termino . "&p=" . ($page - 1) . "";
        @$fuente = Expresiones::fuente($direc, true);
        preg_match_all("/<pre><a target=\'_parent\' href=\'http\:\/\/www\.goear\.com\/listen\/(.*?)\/.*?\'>(.*?) - \(.*?\)<\/a><\/pre>/", $fuente, $dato);
        if (count($dato[0]) > 0) {
            Load::lib('general');
            for ($i = 0; $i < count($dato[0]); $i++) {
                $return[$i]['id'] = $dato[1][$i];
                $return[$i]['titulo'] = $dato[2][$i];
                @$return[$i]['tituloUrl'] = General::slugify($dato[2][$i]);
            }
        }
        else
            $return = false;
        return $return;
    }

    public function datosMusica($cod) {
        Load::lib('expresiones');
        //Load::lib('general');
        $url = 'http://www.goear.com/tracker758.php?f=' . $cod;
        $url = 'http://www.proxyweb.net/index.php?q=' . base64_encode($url) . '&hl=1b6';
        @$fuente = Expresiones::fuente($url, false);
        preg_match_all("/<song path=\"(.*?)\" bild=\".*?\" artist=\"(.*?)\" title=\"(.*?)\"\/>/", $fuente, $dato);
        if (strlen($dato[3][0]) != 0 && strlen($dato[2][0]) != 0) {
            $return['titulo'] = $dato[3][0];
            $return['artista'] = $dato[2][0];
            $return['url'] = $dato[1][0];
            @$return['limpio'] = General::slugify($dato[2][0] . "-" . $dato[3][0]);
            return $return;
        }
        else
            return false;
    }
    public function datosXmlGoear($idG){
        $xml = 'http://www.goear.com/playersong/'.$idG.'/';
        $datos = simplexml_load_file($xml);
        $return = array("titulo"=>$datos->playlist->track['title'],
                        "urlDescarga"=>$datos->playlist->track['href'],
                );
        return $return;
    }

}

?>
